<template>
  <div>
    <div class="textBox">
      <transition name="slide">
        <p class="text" :key="text.id">{{text.val}}</p>
      </transition>
        <p></p>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import qs from 'qs';
import { getUserInfo, changeUser, getCurrentUserDetail,getCurrentUserBoss } from '@/api/api.js'
export default {
  /**
   * 通告栏
   */
  name: 'NoticeBar',
  props: {
    // 渲染数组
    options: {
      type: Array,
      default: () => { return [] }
    }
  },
  data () {
    return {
      textArr: [],
      number: parseInt(5*Math.random())
    }
  },
  computed: {
    text () {
      return {
        id: this.number,
        val: this.textArr[this.number]
      }
    }
  },
  mounted () {
    //this.startMove()
	    if(window.name == ""){
		//console.log("首次被加载");
 	    // 在首次进入页面时我们给window.name设置一个固定值(isRefresh) 
           window.name = "isRefresh"; 
           this.startMove();
        }else if(window.name == "isRefresh"){
		//console.log("页面被刷新");
			this.startMove();
        }
  },
  methods: {
    // startMove () {
    //   // eslint-disable-next-line
    //   let timer = setTimeout(() => {
    //     let index = this.textArr.length === 0 ? 0 : this.textArr.length - 1
    //     //console.log("index:",index);
    //     //console.log("this.textArr.length:",this.textArr.length);
    //     //console.log("this.number:",this.number);
    //     this.number = parseInt(index*Math.random());
    //     //console.log("this.textArr:",this.textArr[this.number]);
    //    // if (this.number === index) {
    //    //   this.number = 0
    //    // } else {
    //    //   this.number += 1
    //    // }
    //     this.startMove()
    //   }, 5000) // 滚动不需要停顿则将2000改成动画持续时间0.5s  本来是60000
    // },
      startMove () {
          let index = this.textArr.length === 0 ? 0 : this.textArr.length - 1
          this.number = parseInt(index*Math.random());
      },
    //获取当前用户工号和名字
    getNowUser () {
          let _this = this;
          getCurrentUserDetail({}).then((result) => {
            if (result.status == "200" && result.data.code == "0") {
    		  //console.log("username",result.data.data.userName);
    		  //console.log("deptNamePath",result.data.data.deptNamePath);
            } else {
              _this.$alert(result.data.msg, _this.$t('cm.tips'));
            }
          }).catch((err) => {
            _this.$alert(err,_this.$t('cm.tips'));
          });
        },
    //测试当前用户的直属上司  需要配合api.js
    //getPersonBoss(){
    //    let _this = this;
	//	  getCurrentUserBoss("P622400").then((result) => {
	//		if (result.status == "200" && result.data.code == "0") {
	//		  console.log("BossUsername",result.data.data.staffName);
	//		} else {
	//		  _this.$alert(result.data.msg, _this.$t('cm.tips'));
	//		}
	//	  }).catch((err) => {
	//		_this.$alert(err,_this.$t('cm.tips'));
	//	  });
    //}
  },
  watch: {
    options: {
      immediate: true,
      handler () {
        // 初始化数据
        this.textArr = this.options
      }
    }
  },
  created () {
     this.getNowUser()
      //this.getPersonBoss()
    }
 // created(){
  //  axios({
  //  method:'post',
  //  url:'http://aepgw-t.gnpjvc.cgnpc.com.cn/hrcenter/getHeaderInWorkDeptByStaffNo?staffNo=PXMWCJA',
  //  data:qs.stringify(this.formData),}).then((res)=>{
  //   console.log(res);
  //  }),
  //    this.getNowUser()
  //}
}
</script>
<style lang="scss">
.textBox {
  font-size: 14;
  width: 100%;
  height: 35px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
  text-align: left;
  .text {
    color: $--color_text;
    width: 100%;
    position: absolute;
    bottom: 6px;
  }
}
.slide-enter-active,
.slide-leave-active {
  transition: all 0.5s linear;
}
.slide-enter {
  transform: translateY(20px) scale(1);
  opacity: 1;
}
.slide-leave-to {
  transform: translateY(-20px) scale(1);
  opacity: 0;
}
</style>
